/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) radix(10) lradix(10) 
// Source File Name:   ProjectTreeListBaseUI.java

package com.kingdee.eas.custom.material;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.kdf.table.ICell;
import com.kingdee.bos.ctrl.kdf.table.KDTSelectManager;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.ctrl.kdf.table.util.KDTableUtil;
import com.kingdee.bos.ctrl.swing.KDMenu;
import com.kingdee.bos.ctrl.swing.KDMenuItem;
import com.kingdee.bos.ctrl.swing.KDTree;
import com.kingdee.bos.ctrl.swing.KDWorkButton;
import com.kingdee.bos.ctrl.swing.tree.DefaultKingdeeTreeNode;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.dao.query.IQueryExecutor;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemCollection;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SorterItemCollection;
import com.kingdee.bos.metadata.entity.SorterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.org.CostCenterOrgUnitInfo;
import com.kingdee.eas.basedata.org.FullOrgUnitInfo;
import com.kingdee.eas.basedata.org.OrgStructureInfo;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.common.client.UIContext;
import com.kingdee.eas.common.client.UIFactoryName;
import com.kingdee.eas.fdc.basedata.CurProjectInfo;
import com.kingdee.eas.fdc.basedata.FDCConstants;
import com.kingdee.eas.fdc.basedata.client.AbstractProjectTreeListBaseUI;
import com.kingdee.eas.fdc.basedata.client.FDCClientUtils;
import com.kingdee.eas.fdc.basedata.client.ProjectTreeBuilder;
import com.kingdee.eas.fdc.contract.client.ContractClientUtils;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.framework.CoreBillBaseInfo;
import com.kingdee.eas.framework.ICoreBase;
import com.kingdee.eas.framework.client.AbstractCoreBillListUI;
import com.kingdee.eas.framework.client.AbstractCoreUI;
import com.kingdee.eas.framework.client.AbstractListUI;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.MsgBox;
import java.awt.event.ActionEvent;
import java.util.HashSet;
import java.util.Iterator;
import javax.swing.KeyStroke;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import org.apache.log4j.Logger;

// Referenced classes of package com.kingdee.eas.fdc.basedata.client:
//            AbstractProjectTreeListBaseUI, ProjectTreeBuilder, FDCClientUtils

public abstract class MaterialBase2ListUI extends AbstractProjectTreeListBaseUI
{

    public MaterialBase2ListUI()
        throws Exception
    {
    }

    public void actionAddNew_actionPerformed(ActionEvent e)
        throws Exception
    {
        checkBeforeAddNew(e);
        super.actionAddNew_actionPerformed(e);
    }

    protected void checkBeforeAddNew(ActionEvent e)
    {
        if(!e.getActionCommand().equals("FDCCostSplit"))
            FDCClientUtils.checkSelectProj(this, getProjSelectedTreeNode());
    }

    public void actionEdit_actionPerformed(ActionEvent e)
        throws Exception
    {
        checkBeforeEdit();
        super.actionEdit_actionPerformed(e);
    }

    public void actionRemove_actionPerformed(ActionEvent e)
        throws Exception
    {
        checkBeforeRemove();
        super.actionRemove_actionPerformed(e);
    }

    protected void Remove()
        throws Exception
    {
        removeBill();
    }

    protected void removeBill()
        throws Exception
    {
        int selectRows[] = KDTableUtil.getSelectedRows(getMainTable());
        com.kingdee.bos.dao.IObjectPK arrayPK[] = new ObjectUuidPK[selectRows.length];
        boolean canRemove = true;
        try
        {
            for(int i = 0; i < selectRows.length; i++)
            {
                String id = (String)getMainTable().getCell(selectRows[i], getKeyFieldName()).getValue();
                checkRef(id);
                arrayPK[i] = new ObjectUuidPK(id);
                setOprtState("REMOVE");
                pubFireVOChangeListener(arrayPK[i].toString());
            }

        }
        catch(Throwable ex)
        {
            handUIException(ex);
            canRemove = false;
            SysUtil.abort();
        }
        if(canRemove)
        {
            getRemoteInterface().delete(arrayPK);
            showOprtOKMsgAndRefresh();
        }
    }

    protected String getEditUIName()
    {
        return null;
    }

    protected ICoreBase getBizInterface()
        throws Exception
    {
        return null;
    }

    protected IObjectValue createNewData()
    {
        return null;
    }

    protected void prepareUIContext(UIContext uiContext, ActionEvent e)
    {
        super.prepareUIContext(uiContext, e);
        com.kingdee.bos.ui.face.ItemAction act = getActionFromActionEvent(e);
        Object userObject2 = getProjSelectedTreeNode().getUserObject();
        if(userObject2 instanceof CurProjectInfo)
        {
            BOSUuid projId = ((CurProjectInfo)userObject2).getId();
            uiContext.put("projectId", projId);
        }
        java.util.Set leafNodesIdSet = new HashSet();
        TreeNode projRoot = (TreeNode)treeProject.getModel().getRoot();
        FDCClientUtils.genProjLeafNodesIdSet(projRoot, leafNodesIdSet);
        uiContext.put("projLeafNodesIdSet", leafNodesIdSet);
    }

    public void onLoad()
        throws Exception
    {
        super.onLoad();
        buildProjectTree();
        freezeTableColumn();
        updateButtonStatus();
        actionQuery.setEnabled(false);
        actionQuery.setVisible(false);
        actionMultiapprove.setEnabled(false);
        actionMultiapprove.setVisible(false);
        actionNextPerson.setEnabled(false);
        actionNextPerson.setVisible(false);
        actionAuditResult.setEnabled(false);
        actionAuditResult.setVisible(false);
        treeProject.setSelectionRow(0);
    }

    private void buildProjectTree()
        throws Exception
    {
        ProjectTreeBuilder projectTreeBuilder = new ProjectTreeBuilder();
        projectTreeBuilder.build(this, treeProject, actionOnLoad);
        treeProject.setShowsRootHandles(true);
    }

    protected void updateButtonStatus()
    {
        super.updateButtonStatus();
        if(!SysContext.getSysContext().getCurrentCostUnit().isIsBizUnit())
        {
            actionAddNew.setEnabled(false);
            actionEdit.setEnabled(false);
            actionRemove.setEnabled(false);
            actionAddNew.setVisible(false);
            actionEdit.setVisible(false);
            actionRemove.setVisible(false);
            menuEdit.setVisible(false);
        }
    }

    protected void setActionState()
    {
        super.setActionState();
        updateButtonStatus();
    }

    protected String getEditUIModal()
    {
        return UIFactoryName.NEWTAB;
    }

    protected void showOprtOKMsgAndRefresh()
        throws Exception
    {
        FDCClientUtils.showOprtOK(this);
        refreshList();
    }

    protected void beforeExcutQuery(EntityViewInfo ev)
    {
        super.beforeExcutQuery(ev);
    }

    protected void execQuery()
    {
        EntityViewInfo ev = getMainQuery();
        if(ev.getSorter().size() == 0 || ev.getSorter().size() == 1 && ev.getSorter().contains(new SorterItemInfo("id")))
        {
            SorterItemCollection sorters = getSorter();
            if(sorters != null)
            {
                int i = 0;
                Iterator iter = sorters.iterator();
                do
                {
                    if(!iter.hasNext())
                        break;
                    SorterItemInfo sorter = (SorterItemInfo)iter.next();
                    if(!ev.getSorter().contains(sorter))
                        ev.getSorter().addObject(i++, sorter);
                } while(true);
            }
        }
        super.execQuery();
    }

    protected IQueryExecutor getQueryExecutor(IMetaDataPK queryPK, EntityViewInfo viewInfo)
    {
        viewInfo = (EntityViewInfo)mainQuery.clone();
        try
        {
            FilterInfo filter = getTreeFilter();
            if(viewInfo.getFilter() != null)
                viewInfo.getFilter().mergeFilter(filter, "and");
            else
                viewInfo.setFilter(filter);
            filterByBillState(viewInfo);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return super.getQueryExecutor(queryPK, viewInfo);
    }

    protected boolean isIgnoreCUFilter()
    {
        return true;
    }

    protected void treeProject_valueChanged(TreeSelectionEvent e)
        throws Exception
    {
        super.treeProject_valueChanged(e);
        treeSelectChange();
    }

    protected void treeSelectChange()
        throws Exception
    {
        execQuery();
        if(getMainTable().getRowCount() > 0)
            getMainTable().getSelectManager().select(0, 0);
    }

    protected FilterInfo getTreeFilter()
        throws Exception
    {
        FilterInfo filter = getTreeSelectChangeFilter();
        FilterItemCollection filterItems = filter.getFilterItems();
        if(getProjSelectedTreeNode() != null && (getProjSelectedTreeNode().getUserObject() instanceof CoreBaseInfo))
        {
            CoreBaseInfo projTreeNodeInfo = (CoreBaseInfo)getProjSelectedTreeNode().getUserObject();
            if(projTreeNodeInfo instanceof OrgStructureInfo)
            {
                BOSUuid id = ((OrgStructureInfo)projTreeNodeInfo).getUnit().getId();
                java.util.Set idSet = FDCClientUtils.genOrgUnitIdSet(id);
                filterItems.add(new FilterItemInfo("orgUnit.id", idSet, CompareType.INCLUDE));
            } else
            if(projTreeNodeInfo instanceof CurProjectInfo)
            {
                BOSUuid id = projTreeNodeInfo.getId();
                java.util.Set idSet = FDCClientUtils.genProjectIdSet(id);
                filterItems.add(new FilterItemInfo("curProject.id", idSet, CompareType.INCLUDE));
            }
        }
        filterItems.add(new FilterItemInfo("curProject.isEnabled", Boolean.TRUE));
        return filter;
    }

    public DefaultKingdeeTreeNode getProjSelectedTreeNode()
    {
        return (DefaultKingdeeTreeNode)treeProject.getLastSelectedPathComponent();
    }

    protected void freezeTableColumn()
    {
    }

    public void actionAudit_actionPerformed(ActionEvent e)
        throws Exception
    {
        checkSelected();
        checkBillState(getStateForAudit(), "selectRightRowForAudit");
        audit(ContractClientUtils.getSelectedIdValues(getMainTable(), getKeyFieldName()));
        showOprtOKMsgAndRefresh();
    }

    public void actionUnAudit_actionPerformed(ActionEvent e)
        throws Exception
    {
        checkSelected();
        checkBillState(getStateForUnAudit(), "selectRightRowForUnAudit");
        java.util.List selectedIdValues = ContractClientUtils.getSelectedIdValues(getMainTable(), getKeyFieldName());
        String id;
        for(Iterator iter = selectedIdValues.iterator(); iter.hasNext(); checkRef(id))
            id = (String)iter.next();

        unAudit(selectedIdValues);
        showOprtOKMsgAndRefresh();
    }

    protected void checkBillState(String state, String res)
        throws Exception
    {
        java.util.List idList = ContractClientUtils.getSelectedIdValues(getMainTable(), getKeyFieldName());
        java.util.Set idSet = ContractClientUtils.listToSet(idList);
        EntityViewInfo view = new EntityViewInfo();
        FilterInfo filter = new FilterInfo();
        filter.getFilterItems().add(new FilterItemInfo("id", idSet, CompareType.INCLUDE));
        view.setFilter(filter);
        view.getSelector().add("id");
        view.getSelector().add("state");
        CoreBaseCollection coll = getRemoteInterface().getCollection(view);
        Iterator iter = coll.iterator();
        do
        {
            if(!iter.hasNext())
                break;
            CoreBaseInfo element = (CoreBaseInfo)iter.next();
            FDCClientUtils.checkBillInWorkflow(this, element.getId().toString());
            if(!element.getString(getBillStatePropertyName()).equals(state))
            {
                MsgBox.showWarning(this, ContractClientUtils.getRes(res));
                abort();
            }
        } while(true);
    }

    protected String getStateForAudit()
    {
        return "2SUBMITTED";
    }

    protected String getStateForUnAudit()
    {
        return "4AUDITTED";
    }

    protected String getBillStatePropertyName()
    {
        return "state";
    }

    protected abstract ICoreBase getRemoteInterface()
        throws BOSException;

    protected abstract void audit(java.util.List list)
        throws Exception;

    protected abstract void unAudit(java.util.List list)
        throws Exception;

    protected void checkBeforeEdit()
        throws Exception
    {
        checkSelected();
        CoreBaseInfo billInfo = getRemoteInterface().getValue(new ObjectUuidPK(getSelectedKeyValue()));
        String billState = billInfo.getString(getBillStatePropertyName());
        String states[] = getBillStateForEditOrRemove();
        boolean pass = false;
        for(int i = 0; i < states.length; i++)
            if(billState.equals(states[i]))
                pass = true;

        if(!pass)
        {
            MsgBox.showWarning(this, ContractClientUtils.getRes("cantEdit"));
            SysUtil.abort();
        }
    }

    protected String[] getBillStateForEditOrRemove()
    {
        return (new String[] {
            "1SAVED", "2SUBMITTED"
        });
    }

    protected void checkBeforeRemove()
        throws Exception
    {
        checkSelected();
        java.util.List idList = ContractClientUtils.getSelectedIdValues(getMainTable(), getKeyFieldName());
        if(idList == null)
            return;
        java.util.Set idSet = ContractClientUtils.listToSet(idList);
        EntityViewInfo view = new EntityViewInfo();
        FilterInfo filter = new FilterInfo();
        filter.getFilterItems().add(new FilterItemInfo("id", idSet, CompareType.INCLUDE));
        view.setFilter(filter);
        view.getSelector().add("id");
        view.getSelector().add(getBillStatePropertyName());
        CoreBaseCollection coll = getRemoteInterface().getCollection(view);
        String states[] = getBillStateForEditOrRemove();
        Iterator iter = coll.iterator();
        do
        {
            if(!iter.hasNext())
                break;
            CoreBillBaseInfo element = (CoreBillBaseInfo)iter.next();
            String billState = element.getString(getBillStatePropertyName());
            boolean pass = false;
            for(int i = 0; i < states.length; i++)
                if(billState.equals(states[i]))
                    pass = true;

            if(!pass)
            {
                MsgBox.showWarning(this, ContractClientUtils.getRes("cantRemove"));
                SysUtil.abort();
            }
        } while(true);
    }

    protected FilterInfo getTreeSelectChangeFilter()
    {
        FilterInfo filter = new FilterInfo();
        FilterItemCollection filterItems = filter.getFilterItems();
        filterItems.add(new FilterItemInfo("curProject.isEnabled", Boolean.TRUE));
        return filter;
    }

    protected void initWorkButton()
    {
        super.initWorkButton();
//        btnAudit.setIcon(FDCConstants.ICON_AUDIT);
//        btnUnAudit.setIcon(FDCConstants.ICON_UNAUDIT);
//        menuItemAudit.setIcon(FDCConstants.ICON_AUDIT);
//        menuItemUnAudit.setIcon(FDCConstants.ICON_UNAUDIT);
        menuItemAudit.setAccelerator(KeyStroke.getKeyStroke("ctrl U"));
        actionAudit.putValue("AcceleratorKey", KeyStroke.getKeyStroke("ctrl U"));
        menuItemAudit.setText(menuItemAudit.getText().replaceAll("\\(A\\)", "") + "(A)");
        menuItemAudit.setMnemonic('A');
        actionAudit.putValue("AcceleratorKey", KeyStroke.getKeyStroke("ctrl shift U"));
        menuItemUnAudit.setText(menuItemUnAudit.getText().replaceAll("\\(U\\)", "") + "(U)");
        menuItemUnAudit.setAccelerator(KeyStroke.getKeyStroke("ctrl shift U"));
        menuItemUnAudit.setMnemonic('U');
    }

    protected void checkRef(String s)
    {
    }

    protected SorterItemCollection getSorter()
    {
        SorterItemCollection sorter = new SorterItemCollection();
        sorter.add(new SorterItemInfo("state"));
        return sorter;
    }

    protected void filterByBillState(EntityViewInfo entityviewinfo)
    {
    }

    private static final Logger logger;

    static 
    {
        logger = CoreUIObject.getLogger(com.kingdee.eas.fdc.basedata.client.ProjectTreeListBaseUI.class);
    }
}



/***** DECOMPILATION REPORT *****

	DECOMPILED FROM: E:\dahua\lib\server\eas\fdc_basedata-server.jar


	TOTAL TIME: 235 ms


	JAD REPORTED MESSAGES/ERRORS:

Couldn't fully decompile method _mthclass$
Couldn't resolve all exception handlers in method _mthclass$

	EXIT STATUS:	0


	CAUGHT EXCEPTIONS:

 ********************************/